package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IEconomicTypeDao;
import com.hy.erp.inventory.dao.interfaces.IPositionPropertyDao;
import com.hy.erp.inventory.pojo.PositionProperty;
import com.hy.erp.inventory.pojo.interfaces.IEconomicType;
import com.hy.erp.inventory.pojo.interfaces.IPositionProperty;
import com.hy.erp.inventory.service.interfaces.IPositionPropertyService;
@ Name ( "positionPropertyService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class PositionPropertyService extends AbstractBusinessService < IPositionProperty > implements IPositionPropertyService 
{

	@ Override
	public boolean addPositionProperty (
											IPositionProperty positionProperty )
	{






		if ( null == positionProperty)
		{
			return true ;
		}
		
		else
		{
		

			IPositionPropertyDao positionPropertyDao =
			                       ( IPositionPropertyDao ) this
			                                          .getDao ( IPositionProperty.class ) ;
			
			return positionPropertyDao
			                .persist ( positionProperty ) ;
		}
		
	
	
	
	
	
	
	}

	@ Override
	public boolean modifyPositionProperty (
											IPositionProperty positionProperty )
	{






		if ( ( null == positionProperty )
			     || ( null == positionProperty
			                                .getIdentifier ( ) )
			     || ( positionProperty
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{

				IPositionPropertyDao positionPropertyDao =
                    ( IPositionPropertyDao ) this
                                       .getDao ( IPositionProperty.class ) ;

					
				if ( null == positionProperty )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (positionPropertyDao
				                  .merge ( positionProperty ) != null ) ;
			}
		
	
	
	
	
	
	
	}

	@ Override
	public Integer removePositionProperty (
											String [ ] positionPropertyIds )
	{






		if ( ( null == positionPropertyIds)
			     || ( positionPropertyIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{




				IPositionPropertyDao positionPropertyDao =
                    ( IPositionPropertyDao ) this
                                       .getDao ( IPositionProperty.class ) ;

				
		

				return positionPropertyDao
				                .remove ( positionPropertyIds ) ;
			}
	
	
	
	
	
	
	}

	@ Override
	public String [ ] addPositionProperty (
											Object [ ] objects )
	{
		IPositionPropertyDao positionPropertyDao =
            ( IPositionPropertyDao ) this
                               .getDao ( IPositionProperty.class ) ;
		PositionProperty[] properties=new PositionProperty[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			PositionProperty property=( PositionProperty ) objects[i];
			properties[i]=property;
		}
		return positionPropertyDao.persist ( properties ) ;
	}

	@ Override
	public List < IPositionProperty > getAllPositionProperty ( )
	{
		IPositionPropertyDao positionPropertyDao =
            ( IPositionPropertyDao ) this
                               .getDao ( IPositionProperty.class ) ;
		return positionPropertyDao.find ( ) ;
	}

	@ Override
	public String [ ] modifyPositionProperty (
												Object [ ] objects )
	{

		if (  null == objects ) 
				{
					return null;
				}
				else
				{
					IPositionPropertyDao positionPropertyDao =
			            ( IPositionPropertyDao ) this
			                               .getDao ( IPositionProperty.class ) ;
					PositionProperty[] types=new PositionProperty[objects.length];
		            for(int i=0;i<objects.length;i++)
		            {
		            	PositionProperty type=( PositionProperty ) objects[i];
		            	types[i]=type;
		            }
					
					return positionPropertyDao.merge ( types );
				}
	}

}
